package com.briup.cms.util;

import lombok.Data;

/**
 * {"code":"业务的响应状态表示业务操作是否成功",
 *  "message":"状态码的信息",
 *  "data":"查询数据"}
 *
 * 设计一个类实现RESTFul风格下的统一响应格式
 * 所有的控制器方法的返回值必须是Result类型的对象
 */
public class Result {
    private Integer code;
    private String message;
    private Object data;//数据类型不确定

    public Result() {
    }
    //表示新增 修改 删除时返回数据对象
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    //查询时，返回数据对象
    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public Result(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
